<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$jigouid=$this->checklogin();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid'],'jigouid'=>$jigouid);
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_chengedu_students',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($return['list'] as &$item){
		$item['zhaopian']=$item['zhaopian']?1:0;
		$item['codeimage01']=$item['codeimage01']?1:0;
		$item['codeimage02']=$item['codeimage02']?1:0;
		$item['biyeimg']=$item['biyeimg']?1:0;
		$item['beianimg']=$item['beianimg']?1:0;
		$item['otherimg']=$item['otherimg']?1:0;
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'tabs'=>array(
			array('op'=>'list','title'=>'学生管理'),
			array('op'=>'edit','title'=>'添加学生'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(			
			array('name'=>'name','title'=>'姓名','type'=>'string'),
			array('name'=>'mobile','title'=>'电话','type'=>'string'),
			array('name'=>'email','title'=>'邮箱','type'=>'string'),
			array('name'=>'zhaopian','title'=>'蓝底照片','type'=>'radio','options'=>'isadd'),
			array('name'=>'codeimage01','title'=>'身份证正面','type'=>'radio','options'=>'isadd'),
			array('name'=>'codeimage02','title'=>'身份证反面','type'=>'radio','options'=>'isadd'),			
			array('name'=>'biyeimg','title'=>'毕业证','type'=>'radio','options'=>'isadd'),
			array('name'=>'beianimg','title'=>'学历电子备案表','type'=>'radio','options'=>'isadd'),
			array('name'=>'otherimg','title'=>'其他证明','type'=>'radio','options'=>'isadd'),
		),'action'=>array(
			array('type'=>'href','action'=>'/manage.students/edit/','title'=>'查看并编辑'),
		)),
		'search'=>array(
			array('name'=>'name','width'=>10,'type'=>'string','title'=>'学生姓名'),
			array('name'=>'pici_id','width'=>10,'title'=>'批次','type'=>'select','options'=>'pici'),
			array('name'=>'type','width'=>10,'title'=>'类型','type'=>'select','options'=>'students_type'),
			array('name'=>'zhuanye_id','width'=>10,'title'=>'专业','type'=>'select','options'=>'zhuanye'),
			array('name'=>'ceng_type','width'=>10,'title'=>'层次','type'=>'select','options'=>'ceng_type'),
			array('name'=>'school_id','width'=>10,'title'=>'学校','type'=>'select','options'=>'school'),
		)
	);
	$return['pici']=pdo_getall('jy_chengedu_pici',array('uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
	$return['zhuanye']=pdo_getall('jy_chengedu_zhuanye',array('uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
	$return['school']=pdo_getall('jy_chengedu_school',array('uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
	$return['ceng_type']=pdo_getall('jy_chengedu_ceng_type',array('uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
	$return['students_type']=pdo_getall('jy_chengedu_students_type',array('uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
	$return['status']=$this->students_status;
	$return['status']=$this->students_status;
	$return['isadd']=array('未添加','已添加');
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_chengedu_students',array('id'=>$id));
	}else{
		$item=array();
	}
	$item['pcd']=json_decode($item['pcd'],true);
    $return['item']=$item;
	$return['status']=array('0'=>'不显示','1'=>'显示');
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'学生资料',
		'tabs'=>array(
			array('op'=>'list','title'=>'学生管理'),
			array('op'=>'edit','title'=>'添加学生')
		),
		'edit'=>array(
			array('type'=>'select5','name'=>'groupid','options'=>'group','title'=>'请选择教育形式',
				'name2'=>'pici_id','options2'=>'pici','title2'=>'请选择批次',
				'name3'=>'school_id','options3'=>'school','title3'=>'请选择招生学校',
				'name4'=>'ceng_type','options4'=>'ceng_type','title4'=>'请选择层次',
				'name5'=>'zhuanye_id','options5'=>'zhuanye','title5'=>'请选择专业'
			),
			array('name'=>'type','title'=>'请选择招生单位','type'=>'select','options'=>'students_type'),
			array('name'=>'pcd','title'=>'学生所在地','type'=>'pcd'),
			array('name'=>'name','title'=>'姓名','type'=>'string','must'=>true),
			array('name'=>'mobile','title'=>'手机号','type'=>'string','must'=>true),
			array('name'=>'codenumber','title'=>'身份证','type'=>'string','must'=>true),
			array('name'=>'national','title'=>'民族','type'=>'string','must'=>true),
			array('name'=>'huji','title'=>'户籍','type'=>'string'),
			array('name'=>'zhenzhi','title'=>'政治面貌','type'=>'string'),
			array('name'=>'xueli','title'=>'前置学历','type'=>'string'),
			array('name'=>'email','title'=>'邮箱地址','type'=>'string','must'=>true),
			array('name'=>'username','title'=>'用户名称','type'=>'string'),
			array('name'=>'password','title'=>'密码','type'=>'string'),
			array('name'=>'number','title'=>'学号','type'=>'string'),
			array('name'=>'sex','title'=>'性别','type'=>'radio','options'=>'sex'),
			array('name'=>'zhaopian','title'=>'2寸蓝底照片','type'=>'image','must'=>true),
			array('name'=>'codeimage01','title'=>'身份证正面','type'=>'image','must'=>true),
			array('name'=>'codeimage02','title'=>'身份证反面','type'=>'image','must'=>true),
			array('name'=>'biyeimg','title'=>'毕业证','type'=>'image','must'=>true),
			array('name'=>'beianimg','title'=>'学历电子备案表','type'=>'image'),
			array('name'=>'otherimg','title'=>'其他证明','type'=>'image'),
			array('name'=>'jiaofee','title'=>'缴费情况','type'=>'string'),
			array('name'=>'xuexi','title'=>'学习进度','type'=>'string'),
			array('name'=>'tongkao','title'=>'统考情况','type'=>'string'),
			array('name'=>'lunwen','title'=>'论文','type'=>'string'),
			array('name'=>'xuewei','title'=>'学位申请','type'=>'string'),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),			
		)
	);
	$return['status']=$this->students_status;
	$return['sex']=array('1'=>'男','2'=>'女');
	$return['group']=pdo_getall('jy_chengedu_school_group',array('uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
	foreach($return['group'] as &$gv){
		$gv['pici']=pdo_getall('jy_chengedu_pici',array('groupid'=>$gv['id'],'uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
		foreach($gv['pici'] as &$pv){
			$pv['school']=pdo_getall('jy_chengedu_school',array('pici_id'=>$pv['id'],'uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
			foreach($pv['school'] as &$sv){
				$sv['ceng_type']=pdo_getall('jy_chengedu_ceng_type',array('school_id'=>$sv['id'],'uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
				foreach($sv['ceng_type'] as &$cv){
					$cv['zhuanye']=pdo_getall('jy_chengedu_zhuanye',array('ceng_type'=>$cv['id'],'uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
				}
			}
		}
	}
	$return['students_type']=pdo_getall('jy_chengedu_students_type',array('uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['name'] ){
		exi('请填写姓名','error');
	}
	if(!$postdata['groupid'] ){
		exi('请选择学校类型','error');
	}
	if(!$postdata['school_id'] ){
		exi('请选择学校','error');
	}
	if(!$postdata['zhaopian'] ){
		exi('请上传2寸蓝底照片','error');
	}
	if(!$postdata['codeimage01'] ){
		exi('请上传身份证正面','error');
	}
	if(!$postdata['codeimage02'] ){
		exi('请上传身份证反面','error');
	}
	if(!$postdata['biyeimg'] ){
		exi('请上传毕业证','error');
	}
	$postdata['pcd']=ijson_encode($postdata['pcd']);
	$data=array_fields(array(
		'pici_id',
		'school_id',
		'groupid',
		'zhuanye_id',
		'type',
		'ceng_type',
		'name',
		'number',
		'sex',
		'minzu',
		'mobile',
		'email',
		'username',
		'pcd',
		'zhaopian',
		'biyeimg',
		'beianimg',
		'otherimg',
		'codenumber',
		'codeimage01',
		'codeimage02',
		'paixu',
		'national',
		'huji',
		'zhenzhi',
		'xueli',
		'jiaofee',
		'xuexi',
		'tongkao',
		'lunwen',
		'xuewei',
		'remark',
		'status',
	),$postdata);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_chengedu_students',$data,array('id'=>$id));
		exi('设置成功！','','/manage.codeimg/');
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['jigouid']=$jigouid;
		$data['createtime']=time();
		pdo_insert('jy_chengedu_students',$data);
		exi('添加成功！','','/manage.codeimg/');
	}
}
if($_RQ['op']=='export'){
	if(!empty($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
	}
	//创建时间
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$params=array('uniacid'=>$_SESSION['uniacid'],'jigouid'=>$jigouid);
	$list=pdo_getall('jy_chengedu_students',$params);
	$status=array('1'=>'待发货','2'=>'待收货','3'=>'已完成','4'=>'已关闭');
	$paytype=array('wechat'=>'微信支付','credit'=>'余额支付');
	$ispay=array('0'=>'未支付','1'=>'已支付');
	foreach($list as &$v){
		$v['pici_id']=pdo_getcolumn('jy_chengedu_pici',array('id'=>$v['pici_id'],'uniacid'=>$_SESSION['uniacid']),'title');
		$v['type']=pdo_getcolumn('jy_chengedu_students_type',array('id'=>$v['type'],'uniacid'=>$_SESSION['uniacid']),'title');
		$v['zhuanye_id']=pdo_getcolumn('jy_chengedu_zhuanye',array('id'=>$v['zhuanye_id'],'uniacid'=>$_SESSION['uniacid']),'title');
		$v['ceng_type']=pdo_getcolumn('jy_chengedu_ceng_type',array('id'=>$v['ceng_type'],'uniacid'=>$_SESSION['uniacid']),'title');
		$v['school_id']=pdo_getcolumn('jy_chengedu_school',array('id'=>$v['school_id'],'uniacid'=>$_SESSION['uniacid']),'title');
		$v['status']=$this->students_status[$v['status']];
	}
	$header=array(
		'pici_id'=>'批次',
		'type'=>'类型',
		'zhuanye_id'=>'专业',
		'ceng_type'=>'层次',
		'school_id'=>'学校',
		'name'=>'姓名',
		'codenumber'=>'身份证',
		'status'=>'状态',
	);
	cfc('tools')->export2excel($header,$list,'学生');
}
if($_RQ['op']=='setstatus'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		$update=array('status'=>intval($post['status']));
		pdo_update('jy_chengedu_students',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		exi('设置成功！','','//list/');
	}
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_chengedu_students',array('id'=>$id),array('id','status'));
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'审核操作',
	);
	$htmls['edit']=array(
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),		
	);
	$return['htmls']=$htmls;
	$return['status']=$this->students_status;
	exi($return);
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_chengedu_students',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_chengedu_students',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>